import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import autoprefixer from 'autoprefixer'
import postCssPxToRem from 'postcss-pxtorem'
import { createSvg } from './src/utils/svg'

// 实现@等于./ src--绝对路径
import { resolve } from 'path'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { VantResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		vue(), // 以下两项是为配置Element-plus自动按需导入
		createSvg('./src/icons/svg/'),
		AutoImport({
			resolvers: [ElementPlusResolver()]
		}),
		Components({
			dts: false, // 关闭：自动生成 组件类型声明文件
			resolvers: [ElementPlusResolver(), VantResolver()]
		})
	],
	resolve: {
		// 设置文件./src路径为 @
		alias: [
			{
				find: '@',
				replacement: resolve(__dirname, './src')
			}
		]
	},
	css: {
		postcss: {
			plugins: [
				autoprefixer({
					overrideBrowserslist: ['Android 4.1', 'iOS 7.1', 'Chrome > 31', 'ff > 31', 'ie >= 8']
				}),
				postCssPxToRem({
					// 自适应，px>rem转换
					rootValue: 37.5, // 75表示750设计稿，37.5表示375设计稿
					propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
					selectorBlackList: ['norem'] // 过滤掉norem-开头的class，不进行rem转换
				})
			]
		},
		preprocessorOptions: {
			scss: {
				additionalData: `@import "./src/styles/main.scss";` // 此处全局的scss文件
			}
		}
	}
})
